﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace SQLServerOptimizer.PL.WPF
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            if (e.Args.Length != 0)
            {
                if (e.Args[0] == "ScheduledScan")
                {

                    new RunScheduled().scan(this);

                }
                else if (e.Args[0] == "PerformanceTrace")
                {

                    new SQLServerHealthCheck.SQLServer.CollectPerformanceTraceData().CollectData(Convert.ToInt32(e.Args[1]));
                    this.Shutdown();
                }


            }
            else
            {
                EventManager.RegisterClassHandler(typeof(TextBox),
          TextBox.GotFocusEvent,
          new RoutedEventHandler(TextBox_GotFocus));
                base.OnStartup(e);

                EventManager.RegisterClassHandler(typeof(TextBox),
                TextBox.GotMouseCaptureEvent,
                new RoutedEventHandler(TextBox_GotMouseCapture));

                EventManager.RegisterClassHandler(typeof(TextBox),
             TextBox.PreviewMouseUpEvent,
             new RoutedEventHandler(TextBox_PreviewMouseUpEvent));
                new MainWindow().ShowDialog();
                this.Shutdown();

            }
        }
        void TextBox_PreviewMouseUpEvent(object sender, RoutedEventArgs e)
        {
            (sender as TextBox).SelectAll();
            (sender as TextBox).ReleaseMouseCapture();
            e.Handled = true;

        }
        void TextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            (sender as TextBox).SelectAll();

        }

        void TextBox_GotMouseCapture(object sender, RoutedEventArgs e)
        {

            (sender as TextBox).SelectAll();
        }

    }
}
